//
//  GTCommontHeader.h
//  Easy_Store
//
//  Created by SongZhiyuan on 14/9/17.
//  Copyright (c) 2014年 Mac4. All rights reserved.
//

#import <UIKit/UIKit.h>

#ifndef iphone6_Fix_Demo_GTCommontHeader_h
#define iphone6_Fix_Demo_GTCommontHeader_h

#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度，兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度，兼容性测试/

//以iphone5 为基础 返回 6 ，6plus 的高度
CG_INLINE CGFloat GTFixHeightFlaot(CGFloat height) {
    CGRect mainFrme = [[UIScreen mainScreen] applicationFrame];
    if (mainFrme.size.height/1096*2 < 1) {
        return height;
    }
    height = height*mainFrme.size.height/1096*2;
    
    return height;
}

CG_INLINE CGFloat GTReHeightFlaot(CGFloat height) {
    
    CGRect mainFrme = [[UIScreen mainScreen] applicationFrame];
    if (mainFrme.size.height/1096*2 < 1) {
        return height;
    }
    height = height*1096/(mainFrme.size.height*2);
    return height;
}

CG_INLINE CGFloat GTFixWidthFlaot(CGFloat width) {
    CGRect mainFrme = [[UIScreen mainScreen] applicationFrame];
    if (mainFrme.size.width/1096*2 < 1) {
        return width;
    }
    width = width*mainFrme.size.width/640*2;
    return width;
}

CG_INLINE CGFloat GTReWidthFlaot(CGFloat width) {
    CGRect mainFrme = [[UIScreen mainScreen] applicationFrame];
    if (mainFrme.size.height/1096*2 < 1) {
        return width;
    }
    width = width*640/mainFrme.size.width/2;
    return width;
}

// 经过测试了, 以iphone5屏幕为适配基础
CG_INLINE CGRect
GTRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = x;
    rect.origin.y = y;
    rect.size.width = GTFixWidthFlaot(width);
    rect.size.height = GTFixHeightFlaot(height);
    return rect;
}



//还原成CGRECT 系统坐标

/**还原成CGRECT 宽度*/
CG_INLINE CGFloat ZYRectWidthFlaot(CGFloat width) {
    CGFloat autoSizeScaleX;
    if(ScreenHeight > 480){
        autoSizeScaleX = ScreenWidth/320;
    }else{
        autoSizeScaleX = 1.0;
    }
    return width/autoSizeScaleX;
}
/**还原成CGRECT 宽度*/
CG_INLINE CGFloat ZYRectHeightFlaot(CGFloat height) {
    
    CGFloat autoSizeScaleX;
    if(ScreenHeight > 480){
        autoSizeScaleX = ScreenWidth/320;
    }else{
        autoSizeScaleX = 1.0;
    }
    return height/autoSizeScaleX;
}
/** 比例加大  Height*/
CG_INLINE CGFloat ZY_HeightFlaot(CGFloat height) {
    
    CGFloat autoSizeScaleX;
    if(ScreenHeight > 480){
        autoSizeScaleX = ScreenWidth/320;
    }else{
        autoSizeScaleX = 1.0;
    }
    return height*autoSizeScaleX;
}


/** 比例加大  Width*/
CG_INLINE CGFloat ZY_WidthFlaot(CGFloat width) {
    CGFloat autoSizeScaleX;
    if(ScreenHeight > 480){
        autoSizeScaleX = ScreenWidth/320;
    }else{
        autoSizeScaleX = 1.0;
    }
    return width*autoSizeScaleX;
}



/**坐标等比例 适配 */
CG_INLINE CGRect
ZYRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGFloat autoSizeScaleX;
    CGFloat autoSizeScaleY;
    
    if(ScreenHeight > 480){
        autoSizeScaleX = ScreenWidth/320;
        autoSizeScaleY = ScreenHeight/568;
    }else{
       autoSizeScaleX = 1.0;
        autoSizeScaleY = 1.0;
    }
        
    CGRect rect;
    rect.origin.x = x * autoSizeScaleX;
    rect.origin.y = y * autoSizeScaleY;
    rect.size.width = width * autoSizeScaleX;
    rect.size.height = height * autoSizeScaleY;
    return rect;
}

#endif
